package org.NooLab.glue.subscription;

import java.util.Vector;

import org.NooLab.glue.MessageBoard;




public class ActiveContextHeaderDescriptions {

	Vector<ContextHeaderDescription> items = new Vector<ContextHeaderDescription>() ;
	
	MessageBoard msgBoard;
	
	public ActiveContextHeaderDescriptions( MessageBoard mb ){
	 
		msgBoard = mb;
		
	}

	
	public Vector<ContextHeaderDescription> getContextHeaderDescriptions() {
		return items;
	}
	
	synchronized public void addItem( ContextHeaderDescription item){
		boolean hb=true;
		int ix;
		
		if (item!=null){
			
			ix = getItemIndexByTransactionID( item.transactionID );
			// if (hb){ hb = item.};
			if (ix<0){
				items.add(item);
			}
		}
	}
	
	synchronized public void removeItem(int index){
		
		if ((index>=0) && (index<items.size())){
			items.remove(index);
		}
	}
	
	synchronized public void removeItemByTransactionID( long tid ){
		int ix = -1;
		
		ix = getItemIndexByTransactionID( tid );
		if ((ix>=0) && (ix<items.size())){
			items.remove(ix);
		}
	}
		
	public int size(){
		return items.size();
	}

	public ContextHeaderDescription getItem( int index){
		
		if ((index<0) || (index>items.size())){
			return null;
		}
		return items.get(index);
	}


	public int getItemIndexByTransactionID( long tid ) {
		
		int index = -1;
		ContextHeaderDescription item;
		
		for (int i=0;i<items.size();i++){
			
			item = items.get(i);
			if ( tid == item.transactionID){
				index = i;
				break ;
			}
		} // i->
		
		return index;
	}
	
	
}

